import requests
from lxml import etree
for i in range(1,10):
    url = "https://alpha.wallhaven.cc/search?q=&categories=001&purity=100&topRange=1M&sorting=toplist&order=desc&page={}".format(1)
    response = requests.get(url)
    response.encoding = "utf-8"#清除乱码
            # print(response.text)
            # print(response.status_code)
    selector = etree.HTML(response.text)
                    #得到图片定位
            # print(response.text)
    picture_tp = selector.xpath('//main[@id="main"]/div[@id="thumbs"]/section/ul/li/figure/img/@data-src')

    print(picture_tp)

        # 下载图片
    def download_picture(pic_url):
        for n in range(len(picture_tp)):
            response = requests.get(pic_url[n])
                 # print(response.content)
            with open('d:\\xin\\picture_tp{}.png'.format(n),'wb+') as f:
                     # f = open('baidu_logo.png','wb+')
                f.write(response.content)
    download_picture(picture_tp)

